package com.oopnet.template.test;

import java.util.Arrays;
import java.util.stream.Stream;

import org.junit.Test;

public class JunitTestDemo {
	@Test
	public void testLambda() throws Exception {

		/**
		 * 每一个lambda 表达式在java8中首先会生成一个私有的静态函数，这个私有的静态函数 在java中使用内部类来实现 lambda
		 * 表达式的,在内部类里调用这个静态函数函数。
		 * 
		 * *****完整实例代码******
		 * 
		 * @FunctionalInterface interface Print<T> { public void print(T x); }
		 *                      public class Lambda { public static void
		 *                      PrintString(String s, Print<String> print) {
		 *                      print.print(s); } private static void
		 *                      lambda$0(String x) { System.out.println(x); }
		 *                      final class $Lambda$1 implements Print{
		 * @Override public void print(Object x) { lambda$0((String)x); } }
		 *           public static void main(String[] args) {
		 *           PrintString("test", new Lambda().new $Lambda$1()); } }
		 */

		String[] datas = new String[] { "peng", "zhao", "li" }; // Effectively
																// final

		Arrays.sort(datas, (v1, v2) -> v1.compareTo(v2));
		Stream.of(datas).forEach(System.out::println);
		// datas=null;
		new Thread(() -> System.out.println(datas.length)).start();

	}

	public static int aMethod(int i) throws Exception {
		try {
			return 10/i;
		} catch (Exception ex) {
			System.out.printf("exception in Method ");
			throw new Exception("exception in a Method");
		} finally {
			System.out.printf("finally ");
		}
	}

	public static void main(String[] args) {
		try {
			aMethod(0);
		} catch (Exception ex) {
			System.out.printf("exception in main ");
		}
		System.out.printf("finished ");
	}
}
